"""""
函数定义
"""
""""
def 函数名(参数列表):
    函数体
    return 返回值列表
"""
def cal(length,width):
    return length*width
result = cal(4,3)
print(result)






"""""
函数返回值
"""
def books(name ,book, day):
    print(f"{name}借阅了书籍《{book}》，借阅{day}天")
books("Nun","yeos",14)

result = books("N","N","89")
print(result)

"""
返回最大值
"""
def number(max,min):
    if max > min:
        return max
    else:
        return min
    print("函数执行完成")
result = number(3,5)
print(result)

"""""
求一个三位数的值
"""
def cal(number):
    high = number // 100
    mid  = number // 10 & 10
    low  = number & 10
    return high,mid,low
result = cal(543)
print(result)

a,b,c = cal(543)
print(a,b,c)







def place(name,place):
    print("名字",name)
    print("地点",place)
place("nun","okk")






def place(name,place):
    print("名字",name)
    print("地点",place)
place(place="okk",name="nun")






"""""
默认参数传递
"""
def place(name,place="okk"):
    print("名字",name)
    print("地点",place)
place(name="nun")






"""""
参数的包裹传递
"""
"使用 * 号来进行对不确定参数的包装"
def lang(*lang):
    print(lang)
lang("Python")
lang("C","C++","Python")

def lang1(name,*lang):
    print(f"{name}喜欢的编程语言如下：")
    for lang2 in lang:
        print(lang)
lang("Nun","Python")
lang("N","C","C++","Python")

def personinfo(**info):
    return info
result = personinfo(id=1,name="Nun",age=19,grade="大三")
print(result)

def personinfo(*lang,**info):
    for key,value in info.items():
        print(f"{key}:{value}")
    print("喜欢语言如下：")
    for lang in lang:
        print(lang,end=" ")
personinfo("N","C","C++","Python",id=1,name="Nun",age=19,grade="大三")

def product(a,b,c):
    return a*b*c
tuple = (22,10,22)
print(product(*tuple))
list = [1,3,4]
print(product(*list))
dict01={
    "a":22,
    "b":23,
    "c":21,
}
print(product(**dict01))



def join(url):
    url = "www."+url+".com"
    return url
url = input("您的网站")
url01 = join(url)
print("url",url) 
print("url01",url01) 

def shop(goods_list):
    goods_list.append("OK")
    return goods_list
shop_list = ["n","m"]
"可以对shop()中的参数进行操作，之后再进行函数运行，这里就是先复制列表，然后进行函数的添加程序"
type = shop(shop_list.copy())
print(shop_list)
print(type) 



"""""
哥德巴赫猜想
"""
import math
"判断是否为偶数"
def is_even(number):
    if number %2 == 0:
        return True
    else:
        return False
"判断是否为素数"
def is_prime(number):
    if number < 2:
        return False
    sqrt_number = int(math.sqrt(number))
    for i in range(2,sqrt_number+1):
        if number % i ==0:
            return False
        else:
            return True
"判断一个数能否分为俩个素数的和，并返回一个列表"
def can_sqlit(number):
    equo_list = []
    for i in range(1,number//2+1):
        j = number - i
        if is_prime(i) and is_prime(j):
            equo_list.append(f"{number}={i}+{j}")
    if not equo_list:
        equo_list.append(f"{number}无法分解俩个素数")
    return equo_list
if __name__ == "__main__":
    random_num = input("输入一个大于5的偶数")
    if random_num.isdigit():
        random_num = int(random_num)
        if random_num > 5 and is_even(random_num):
            result_list = can_sqlit(random_num)
            for equo in result_list:
                print(equo)
        else:
            print("输入的数字不合要求")
    else:
        print("输入整数")



"""""
局部变量
"""
"""""""""
def func(a):
    return a
re = func(2)
print(a)
"""
def master_name(name):
    print("宠物主人是：",name)
def pet_name(name):
    print("宠物为：",name)
master_name("Nun")
master_name("NUN")




from calendar import c


x = 3
def func():
    "使用global来进行全局变量"
    global x
    x = x + 11
    print(x)
func()

stu_dict = {
    "a":"22",
    "b":"23",
    "c":"21",
}
def C1():
    stu_dict["c"] = "222"
C1()
print(stu_dict)

def C2():
    stu_dict = {}
    stu_dict["c"] = "222"
    print("C2函数里面的stu_dict()为：",stu_dict)
C2()
print("全局弹道stu_dict为：",stu_dict)




"""""
函数中嵌套函数
"""
def fun01():
    print("fun01()函数开始")
    def fun02():
        print("fun02()函数开始")
        print("fun02()函数结束")
    fun02()
    print("fun01()函数结束")
fun01()

def fun02():
    x=5
    def fun01():
        nonlocal x
        x = x + 1
    fun01()
    print(x)
fun02()






def cal(n):
    if n == 0:
        return 1
    return n*cal(n-1)
num = int(input("输入非零数"))
print(cal(num))







